nums = [-1,0,1,2,-1,-4]
var threeSum = function(nums) {
     nums.sort((a,b)=>(a-b))
     const len=nums.length
     const res=[]
     for(let i=0;i<len-2;i++)
     {
        if(i>0&&nums[i]==nums[i-1])
        {
            continue
        }
        let left=i+1
        let right=len-1
        while(left<right)
        {
            const num=nums[i]+nums[left]+nums[right]
            if(num===0)
            {
                res.push([nums[i],nums[left],nums[right]])
            
            while(left<right&&nums[left]==nums[left+1])
            {
                left++

            }
            while(left<right&&nums[right]==nums[right-1])
            {
                right--
            }
            left++
            right--
        }
        else if(num<0)
        {
            left++
        }
        else if(num>0)
        {
            right--
        }
        }

     }
       return res;
}(nums);
console.log(threeSum)